/**
 * Created by Administrator on 2018/7/2.
 */
// 项目成员列表
var proGrid = null;
var mbersColumnsChange = [{
    id: 'operator_name',
    title: '操作人姓名',
    width: 130,
    type: 'string',
    columnClass: 'text-center',
},{
    id: 'operated_man_name',
    title: '被修改人',
    width: 130,
    type: 'string',
    columnClass: 'text-center',
},{
    id: 'operate_type_name',
    title: '操作',
    width: 75,
    type: 'string',
    columnClass: 'text-center',
},{
    id: 'role_change_to',
    title: '角色变更后',
    // width: 75,
    type: 'string',
    columnClass: 'text-left',
},{
    id: 'update_date',
    title: '时间',
    width: 150,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.update_date);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
        return content;
    }
} ]
var mbersColumns = [{
    id: 'userName',
    title: '人员姓名',
    width: 130,
    type: 'string',
    columnClass: 'text-center',
},  {
    id: 'createTime',
    title: '加入时间',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.createTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
        return content;
    }
}, {
    id: 'proRole',
    title: '担任角色',
    type: 'string',
    // width: 100,
    columnClass: 'text-left',
},{
    id: 'roleDescriptor',
    title: '说明',
    type: 'string',
    columnClass: 'text-left',
    hideType:'lg|md|sm|xs',
}, {
    id: 'operation',
    title: '操作',
    width: 130,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {

        var content = ' ';
        // if(record.proRoleCode.indexOf('XMJL') > -1 || record.proRoleCode.indexOf("XSFZR") > -1 ){
        if(false){
            var met = {
                'XMCYQXC':"loadViewForProMemberAuthority(\'" + record.id + "\');",
            }
            var content = $CertusFormAjax.initOperateAutho($$scope.leftMenu,['XMCYQXC%edit'],met,mbersColumns);
            return content;
        }
        var met = {
            'XMCYQXC':"loadViewForProMemberAuthority(\'" + record.id + "\');",
            'XMCYQXD':'deleteTprojMember(\'' + record.id + '\');'
        }
        var content = $CertusFormAjax.initOperateAutho($$scope.leftMenu,['XMCYQXC%edit','XMCYQXD%delete'],met,mbersColumns);
        return content;
    }
}];

var proGrid = $CertusJsonAjax.dataInit("promemberList", {"proId": proId}, mbersColumns, 'mbersContainer', 'mbersToolBarContainer');

var membersflush = function(){
    $("#changeMember").html("");

    $CertusJsonAjax.ajaxNode("member","listUserOperate",{projId:proId},function(res){
        if(res){
            var library1Option = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',saveProjectAuthority
                exportFileName: '资产库借货信息',
                datas: res,
                columns: mbersColumnsChange,
                gridContainer: 'changeMember',
                toolbarContainer: 'changeMemberContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };

            var library1Grid = $.fn.dlshouwen.grid.init(library1Option);
            library1Grid.load();
            // console.log(res.data);
        }

    })

}

membersflush();


function deleteTprojMember(id) {

    layer.confirm("是否移除项目成员", {
        title: '提示',
        btn: ['确定', '取消'] //按钮
    }, function () {
        //校验 此成员 是否 可删除
        $CertusJsonAjax.ajax("verifyOperateProjMember",{userId:id,proId:proId},function(res){
            if(res.data == "success"){
                for(var j in proGrid.exhibitDatas){
                    if(proGrid.exhibitDatas[j].id == id){
                        $$scope.authoEdit ={};
                        $$scope.authoEdit.baseInfo = proGrid.exhibitDatas[j];
                        $$scope.authoEdit.baseInfo.projId = proId;
                        $$scope.authoEdit.operate = "delete";
                        $CertusJsonAjax.ajaxNode("member","projUserOperate",$$scope.authoEdit,function(res){
                            membersflush();
                        });
                    }
                }
                $CertusFormAjax.ajax("deleteTproMember", {tProjMemberId: id,projId:proId}, function (res) {
                    if (res.data == "success") {
                        proGrid.refresh(true);
                        layer.closeAll();
                    }else if(res.data == "failed"){
                        layer.closeAll();
                        layer.msg("此成员暂时不能删除");
                    }
                })
            }else{
                layer.msg(res.data);
            }

        })


    });

}

$$scope.proMemberRoleAuthorityAdd = function () {
    //调用无参 的 页面加载 函数
    loadViewForProMemberAuthority();
}

function loadViewForProMemberAuthority(id) {
    //id 为 空
    if (id == null || id == "") {
        $("#rightContainer").empty();
        $$http({
            url: "proinfo/edit/edit-members.html",
            method: 'GET',
            data: {},
            dataType: "application/json"
        }).then(function (a) {
            $$scope.htmlxx = a.data
            $CertusFormAjax = $certusUtils;
        }, function (b) {
        })
    } else {
        tProjMemberId = id;
        $("#rightContainer").empty();
        $$http({
            url: "proinfo/edit/edit-members-edit.html",
            method: 'GET',
            data: {},
            dataType: "application/json"
        }).then(function (a) {
            $$scope.htmlxx = a.data
            $CertusFormAjax = $certusUtils;
        }, function (b) {
        })
    }
}